//------------------------------------------------------------------------
//
//	CCGameBox is a game development library for iPhone and iPod Touch.
//
//	Licensed under the BSD license, see LICENSE in root for details.
// 
//	Copyright (c) 2009 James Hui (a.k.a. Dr.Watson)
// 
//	For latest updates, please visit http://www.cocoachina.com
//
//------------------------------------------------------------------------


#ifndef _CCIMAGE_H_
#define _CCIMAGE_H_

#ifdef WIN32
#include <GLES/gl.h>
#else
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#endif

class CCTexture;
class CCColorf;

//////////////////////////////////////////////////////////////////////////
/// Image quad.
/// 
//////////////////////////////////////////////////////////////////////////
class CCImage
{
public:

	//////////////////////////////////////////////////////////////////////////
	/// Constructor.
	/// 
	/// @param tex - Texture of the quad.
	/// @param x - X position of the quad in texture.
	/// @param y - Y position of the quad in texture.
	/// @param width - Width of the quad.
	/// @param height - Height of the quad.
	/// 
	//////////////////////////////////////////////////////////////////////////
	CCImage(CCTexture *tex, float x, float y, float width, float height);
	
	//////////////////////////////////////////////////////////////////////////
	/// Constructor, create q quad with the entire texture.
	///
	/// @param tex - Texture of the quad.
	/// 
	//////////////////////////////////////////////////////////////////////////
	CCImage(CCTexture *tex);

	//////////////////////////////////////////////////////////////////////////
	/// Set blending color of the quad.
	/// 
	/// @param r - red.
	/// @param g - green.
	/// @param b - blue.
	/// @param a - alpha.
	/// 
	//////////////////////////////////////////////////////////////////////////
	//void SetColor(u8 r, u8 g, u8 b, u8 a);
	void SetColor(float r, float g, float b, float a);

	//////////////////////////////////////////////////////////////////////////
	/// Set anchor point of the quad.
	/// 
	/// @param x - X position of the anchor point.
	/// @param y - Y position of the anchor point.
	/// 
	//////////////////////////////////////////////////////////////////////////
	void SetAnchor(float x, float y);
	
	//////////////////////////////////////////////////////////////////////////
	/// Set UV positions of the quad.
	/// 
	/// @param x - X position of the quad in texture.
	/// @param y - Y position of the quad in texture.
	/// @param w - Width of the quad.
	/// @param h - Height of the quad.
	/// 
	//////////////////////////////////////////////////////////////////////////
	void SetTextureRect(float x, float y, float w, float h);

	//////////////////////////////////////////////////////////////////////////
	/// Get UV positions of the quad.
	/// 
	/// @return x - X position of the quad in texture.
	/// @return y - Y position of the quad in texture.
	/// @return w - Width of the quad.
	/// @return h - Height of the quad.
	/// 
	//////////////////////////////////////////////////////////////////////////
	void GetTextureRect(float *x, float *y, float *w, float *h);

	//////////////////////////////////////////////////////////////////////////
	/// Set horizontal flipping.
	/// 
	/// @param hflip - flipping flag;
	/// 
	//////////////////////////////////////////////////////////////////////////
	void SetHFlip(bool hflip) { mHFlipped = hflip; }

	//////////////////////////////////////////////////////////////////////////
	/// Set vetical flipping.
	/// 
	/// @param hflip - flipping flag;
	/// 
	//////////////////////////////////////////////////////////////////////////
	void SetVFlip(bool vflip) { mVFlipped = vflip; }

	//////////////////////////////////////////////////////////////////////////
	/// Use center of the image as the anchor.
	/// 
	//////////////////////////////////////////////////////////////////////////
	void MakeCenterAsAnchor();

	CCTexture* mTexture;

	float mTX0;
	float mTY0;
	float mTX1;
	float mTY1;
	CCColorf mColor;

	float mX;
	float mY;
	float mWidth;
	float mHeight;
	float mAnchorX;
	float mAnchorY;
	float mOffsetX;
	float mOffsetY;

	bool mHFlipped;
	bool mVFlipped;

};


#endif
